package com.akiokevin.plantyourlife.schedule;

public class Scheduler {
	public final int MAX_ENTRIES = 8;
	private ScheduleEntryList mEntries;
	
	public Scheduler() {
		// TODO fill mEntries from database
		//mEntries = Services.getScheduleEntryList();
	}
	
	public ScheduleEntryList getSchedules() {
		return mEntries;
	}
	
	public boolean entryIsFull() {
		return (MAX_ENTRIES <= mEntries.size());
	}
	
	public void addEntry(ScheduleEntry newEntry) {
		if(!entryIsFull() && newEntry != null) {
			// Add entry ordered by time
			int key = 0;
			for(ScheduleEntry entry: mEntries) {
				if(newEntry.compareTo(entry) >= 0) {
					mEntries.add(key, newEntry);
					break;
				}
				key++;
			}
		}
	}
	
	public void removeEntry(int key) {
		mEntries.remove(key);
	}
	
	public ScheduleEntry popEntryAt(int key) {
		ScheduleEntry targetEntry = mEntries.get(key);
		mEntries.remove(key);
		return targetEntry;
	}
}
